<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="学生姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所学专业" prop="specialty">
        <el-input
          v-model="queryParams.specialty"
          placeholder="请输入所学专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有学位证书" prop="diploma">
        <el-select
          v-model="queryParams.diploma"
          placeholder="请选择是否有学位证书"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['member:student-curriculum-vitae:create']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['member:student-curriculum-vitae:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar
        :show-search.sync="showSearch"
        @queryTable="getList"
      />
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="用户id" align="center" prop="id" />
      <el-table-column label="学生id" align="center" prop="studentId" />
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column
        label="学生大头照"
        align="center"
        prop="studentPictureUrl"
      />
      <el-table-column label="当前身份" align="center" prop="identify" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="简历公开状态" align="center" prop="publicStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.INFRA_BOOLEAN_STRING"
            :value="scope.row.publicStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="政治面貌" align="center" prop="political" />
      <el-table-column
        label="出生日期"
        align="center"
        prop="birthday"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="居住城市" align="center" prop="liveCity" />
      <el-table-column
        label="毕业时间"
        align="center"
        prop="graduateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.graduateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="名族" align="center" prop="clan" />
      <el-table-column label="手机号码" align="center" prop="phoneNumber" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="大学名称" align="center" prop="universityName" />
      <el-table-column label="所学专业" align="center" prop="specialty" />
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="年级" align="center" prop="grade" />
      <el-table-column label="是否有学位证书" align="center" prop="diploma">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.INFRA_BOOLEAN_STRING"
            :value="scope.row.diploma"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="在校开始日期"
        align="center"
        prop="universityStartDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.universityStartDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['member:student-curriculum-vitae:update']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            v-hasPermi="['member:student-curriculum-vitae:delete']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="学生大头照">
          <imageUpload v-model="form.studentPictureUrl" />
        </el-form-item>
        <el-form-item label="当前身份" prop="identify">
          <el-input v-model="form.identify" placeholder="请输入当前身份" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio
              v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="简历公开状态" prop="publicStatus">
          <el-radio-group v-model="form.publicStatus">
            <el-radio
              v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="政治面貌" prop="political">
          <el-input v-model="form.political" placeholder="请输入政治面貌" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker
            v-model="form.birthday"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生日期"
          />
        </el-form-item>
        <el-form-item label="居住城市" prop="liveCity">
          <el-input v-model="form.liveCity" placeholder="请输入居住城市" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduateTime">
          <el-date-picker
            v-model="form.graduateTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择毕业时间"
          />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
        </el-form-item>
        <el-form-item label="名族" prop="clan">
          <el-input v-model="form.clan" placeholder="请输入名族" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="大学名称" prop="universityName">
          <el-input
            v-model="form.universityName"
            placeholder="请输入大学名称"
          />
        </el-form-item>
        <el-form-item label="所学专业" prop="specialty">
          <el-input v-model="form.specialty" placeholder="请输入所学专业" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入年级" />
        </el-form-item>
        <el-form-item label="是否有学位证书" prop="diploma">
          <el-radio-group v-model="form.diploma">
            <el-radio
              v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="在校开始日期" prop="universityStartDate">
          <el-date-picker
            v-model="form.universityStartDate"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择在校开始日期"
          />
        </el-form-item>
        <el-form-item label="在校结束日期" prop="universityEndDate">
          <el-date-picker
            v-model="form.universityEndDate"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择在校结束日期"
          />
        </el-form-item>
        <el-form-item label="期望行业(可能多个)" prop="targetIndustry">
          <el-input
            v-model="form.targetIndustry"
            placeholder="请输入期望行业(可能多个)"
          />
        </el-form-item>
        <el-form-item label="期望城市" prop="targetCity">
          <el-input v-model="form.targetCity" placeholder="请输入期望城市" />
        </el-form-item>
        <el-form-item label="最低薪资" prop="lowestSalary">
          <el-input v-model="form.lowestSalary" placeholder="请输入最低薪资" />
        </el-form-item>
        <el-form-item label="最高薪资" prop="highestSalary">
          <el-input v-model="form.highestSalary" placeholder="请输入最高薪资" />
        </el-form-item>
        <el-form-item label="已修课程json" prop="courses">
          <el-input v-model="form.courses" placeholder="请输入已修课程json" />
        </el-form-item>
        <el-form-item label="工作/实习经历json" prop="workExperience">
          <el-input
            v-model="form.workExperience"
            placeholder="请输入工作/实习经历json"
          />
        </el-form-item>
        <el-form-item label="项目经历json" prop="projectExperience">
          <el-input
            v-model="form.projectExperience"
            placeholder="请输入项目经历json"
          />
        </el-form-item>
        <el-form-item label="语言能力json" prop="languageAbility">
          <el-input
            v-model="form.languageAbility"
            placeholder="请输入语言能力json"
          />
        </el-form-item>
        <el-form-item label="专业技能json" prop="specialtyAbility">
          <el-input
            v-model="form.specialtyAbility"
            placeholder="请输入专业技能json"
          />
        </el-form-item>
        <el-form-item label="证书json" prop="certificates">
          <el-input v-model="form.certificates" placeholder="请输入证书json" />
        </el-form-item>
        <el-form-item label="社会实践/活动经历json" prop="practiceExperience">
          <el-input
            v-model="form.practiceExperience"
            placeholder="请输入社会实践/活动经历json"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  createStudentCurriculumVitae,
  updateStudentCurriculumVitae,
  deleteStudentCurriculumVitae,
  getStudentCurriculumVitae,
  getStudentCurriculumVitaePage,
  exportStudentCurriculumVitaeExcel
} from '@/api/member/studentCurriculumVitae'
import ImageUpload from '@/components/ImageUpload'

export default {
  name: 'StudentCurriculumVitae',
  components: {
    ImageUpload
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户简历列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        studentName: null,
        phoneNumber: null,
        email: null,
        specialty: null,
        education: null,
        diploma: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [
          { required: true, message: '学生id不能为空', trigger: 'blur' }
        ],
        studentName: [
          { required: true, message: '学生姓名不能为空', trigger: 'blur' }
        ],
        studentPictureUrl: [
          { required: true, message: '学生大头照不能为空', trigger: 'blur' }
        ],
        identify: [
          { required: true, message: '当前身份不能为空', trigger: 'blur' }
        ],
        sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
        publicStatus: [
          { required: true, message: '简历公开状态不能为空', trigger: 'blur' }
        ],
        political: [
          { required: true, message: '政治面貌不能为空', trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: '出生日期不能为空', trigger: 'blur' }
        ],
        liveCity: [
          { required: true, message: '居住城市不能为空', trigger: 'blur' }
        ],
        graduateTime: [
          { required: true, message: '毕业时间不能为空', trigger: 'blur' }
        ],
        nativePlace: [
          { required: true, message: '籍贯不能为空', trigger: 'blur' }
        ],
        clan: [{ required: true, message: '名族不能为空', trigger: 'blur' }],
        phoneNumber: [
          { required: true, message: '手机号码不能为空', trigger: 'blur' }
        ],
        email: [{ required: true, message: '邮箱不能为空', trigger: 'blur' }],
        universityName: [
          { required: true, message: '大学名称不能为空', trigger: 'blur' }
        ],
        specialty: [
          { required: true, message: '所学专业不能为空', trigger: 'blur' }
        ],
        education: [
          { required: true, message: '学历不能为空', trigger: 'blur' }
        ],
        grade: [{ required: true, message: '年级不能为空', trigger: 'blur' }],
        diploma: [
          {
            required: true,
            message: '是否有学位证书不能为空',
            trigger: 'blur'
          }
        ],
        universityStartDate: [
          { required: true, message: '在校开始日期不能为空', trigger: 'blur' }
        ],
        universityEndDate: [
          { required: true, message: '在校结束日期不能为空', trigger: 'blur' }
        ],
        targetIndustry: [
          {
            required: true,
            message: '期望行业(可能多个)不能为空',
            trigger: 'blur'
          }
        ],
        targetCity: [
          { required: true, message: '期望城市不能为空', trigger: 'blur' }
        ],
        lowestSalary: [
          { required: true, message: '最低薪资不能为空', trigger: 'blur' }
        ],
        highestSalary: [
          { required: true, message: '最高薪资不能为空', trigger: 'blur' }
        ],
        courses: [
          { required: true, message: '已修课程json不能为空', trigger: 'blur' }
        ],
        languageAbility: [
          { required: true, message: '语言能力json不能为空', trigger: 'blur' }
        ],
        specialtyAbility: [
          { required: true, message: '专业技能json不能为空', trigger: 'blur' }
        ],
        certificates: [
          { required: true, message: '证书json不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      const params = { ...this.queryParams }
      // 执行查询
      getStudentCurriculumVitaePage(params).then((response) => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        studentId: undefined,
        studentName: undefined,
        studentPictureUrl: undefined,
        identify: undefined,
        sex: undefined,
        publicStatus: undefined,
        political: undefined,
        birthday: undefined,
        liveCity: undefined,
        graduateTime: undefined,
        nativePlace: undefined,
        clan: undefined,
        phoneNumber: undefined,
        email: undefined,
        universityName: undefined,
        specialty: undefined,
        education: undefined,
        grade: undefined,
        diploma: undefined,
        universityStartDate: undefined,
        universityEndDate: undefined,
        targetIndustry: undefined,
        targetCity: undefined,
        lowestSalary: undefined,
        highestSalary: undefined,
        courses: undefined,
        workExperience: undefined,
        projectExperience: undefined,
        languageAbility: undefined,
        specialtyAbility: undefined,
        certificates: undefined,
        practiceExperience: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加用户简历'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id
      getStudentCurriculumVitae(id).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '修改用户简历'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return
        }
        // 修改的提交
        if (this.form.id != null) {
          updateStudentCurriculumVitae(this.form).then((response) => {
            this.$modal.msgSuccess('修改成功')
            this.open = false
            this.getList()
          })
          return
        }
        // 添加的提交
        createStudentCurriculumVitae(this.form).then((response) => {
          this.$modal.msgSuccess('新增成功')
          this.open = false
          this.getList()
        })
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id
      this.$modal
        .confirm('是否确认删除用户简历编号为"' + id + '"的数据项?')
        .then(function() {
          return deleteStudentCurriculumVitae(id)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams }
      params.pageNo = undefined
      params.pageSize = undefined
      // 执行导出
      this.$modal
        .confirm('是否确认导出所有用户简历数据项?')
        .then(() => {
          this.exportLoading = true
          return exportStudentCurriculumVitaeExcel(params)
        })
        .then((response) => {
          this.$download.excel(response, '${table.classComment}.xls')
          this.exportLoading = false
        })
        .catch(() => {})
    }
  }
}
</script>
